{extend name="$base" /}
{block name="resources"}
{/block}
{block name="main"}
{include file="admin/Express/expressTitle"}
<div class="space-10"></div>
<div class="ncsc-form-goods">
	<!-- 基础设置 -->
	<div class="mod-table">
		<div class="mod-table-head">
			<table class="mytable">
				<tr>
					<td width="20%" style="text-align: left;">
						<button style="margin:0 5px 0 0 !important;" class="btn-common-delete btn-small" onclick="batchDelete()">批量删除</button>
						<button style="margin:0 5px 0 0 !important;" class="btn-common btn-small" onclick="location.href='{:__URL('nspickup/ADMIN_MODULE/shop/addpickuppoint')}';">添加门店</button>
					</td>
					<td width="20%">
						<input type="text" id = 'search_text' placeholder="请输入门店名称" class="input-common"/>
						<input type="button" onclick="searchData()" value="搜索" class="btn-common" />
					</td>
				</tr>
			</table>
			<div class="con style0list">
				<table class="table-class" id="pickupList">
					<colgroup>
						<col style="width: 2%">
						<col style="width: 18%;">
						<col style="width: 18%;">
						<col style="width: 18%;">
						<col style="width: 15%;">
						<col style="width: 13%;">
						<col style="width: 16%;">
					</colgroup>
					<thead>
						<tr align="center">
							<th><i class="checkbox-common"><input id="ckall" type="checkbox" ></i></th>
							<th align="left">门店名称</th>
							<th align="left">地址</th>
							<th>联系人</th>
							<th>联系电话</th>
							<th>发布时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody></tbody>
				</table>
			</div>
		</div>
	</div>
</div>

<!-- 添加审核人员 -->
<div class="modal fade hide" id="addVerificationPerson" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>添加门店审核人员</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="mytable">
						<tbody>
							<tr>
								<td>
									<input id="user_info" class="input-common" type="text" placeholder="输入手机号/邮箱/会员昵称">
									<input type="button" onclick="selectMember();" value="搜索" class="btn-common">
								</td>
							</tr>
						</tbody>
					</table>
					<table class="table-class" id="member_list">
						<colgroup>
							<col style="width: 2%;">
							<col style="width: 29%;">
							<col style="width: 29%;">
							<col style="width: 30%;">
							<col style="width: 10%;">
						</colgroup>
						<thead>
							<th><i class="checkbox-common"><input type="checkbox" onclick="CheckPerSonAll(this)"></i></th>
							<th align="left">会员昵称</th>
							<th>会员邮箱</th>
							<th>会员手机</th>
							<th>状态</th>
						</thead>
						<tbody></tbody>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn-common btn-big" onclick="addPickupAuditor()">保存</button>
				<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

<input type="hidden" id="hidden_pickupPoint_id" value=""/>
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('nspickup/ADMIN_MODULE/shop/pickuppointlist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$("#pickupList tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data['data'][i]['id']+'"></i></td>';
					html += '<td align="left">' + data["data"][i]["name"]+ '</td>';
					html += '<td align="left">'+ data["data"][i]["province_name"]+ '/'+ data["data"][i]["city_name"]+ '/' + data["data"][i]["district_name"]+ '/'+ data["data"][i]["address"]+'</td>';
					
					html += '<td>' + data["data"][i]["contact"]+ '</td>';
					html += '<td>'+data["data"][i]["phone"]+'</td>';
					html += '<td>' + timeStampTurnTime(data["data"][i]["create_time"])+ '</td>';
					html += '<td>';
						html += '<a href="'+__URL('nspickup/ADMIN_MODULE/shop/updatepickuppoint?id='+ data['data'][i]['id'])+'">修改</a>';
						html += '<a onclick="deletepickupPoint('+data['data'][i]['id']+')">删除</a>';
						html += '<a onclick="addAuditor('+data['data'][i]['id']+');">添加审核人员</a>';
					html += '</td>';
					html += '</tr>';
					$("#pickupList tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无自提点</td></tr>';
				$("#pickupList tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}	

function batchDelete() {
	var pickupPoint_id= new Array();
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			pickupPoint_id.push($(this).val());
		}
	});
	if(pickupPoint_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deletepickupPoint(pickupPoint_id);
}

var flag = false;
//删除
function deletepickupPoint(pickupPoint_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
				if(!flag){
					flag = true;
					$.ajax({
						type : "post",
						url : "{:__URL('nspickup/ADMIN_MODULE/shop/deletepickuppoint')}",
						data : {
							"pickupPoint_id" : pickupPoint_id.toString()
						},
						dataType : "json",
						success : function(data) {
							if (data["code"] > 0) {
								showTip(data["message"],'success');
								window.location.href=__URL("nspickup/ADMIN_MODULE/shop/pickuppointlist");
							}else{
								showTip(data["message"],'error');
								flag = false;
							}
						}
					})
				}
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			}
		},
	contentText:"是否删除该自提点？",
	});
}

//全选
function CheckAll(event){
	var checked = event.checked;
	$(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
	if(checked) $(".table-class tbody input[type = 'checkbox']").parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").parent().removeClass("selected");
}

function searchData(){
	LoadingInfo(1);
}

// 添加审核人员
function addAuditor(pickupPoint_id){
	$("#hidden_pickupPoint_id").val(pickupPoint_id);
	$("#addVerificationPerson").modal("show");
}

//查询会员列表
function selectMember(){
	var search_text = $("#user_info").val();
	var v_id = [];
	$("#personList tbody tr input[name='sub']").each(function(){
		v_id.push($(this).val());
	});
	$.ajax({
		type : "post",
		url : __URL("ADMIN_MAIN/verification/getMemberList"),
		data : {"search_text" : search_text, "v_id" : v_id.toString()},
		success : function(data) {
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';

					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["uid"]+'" ></i></td>';

					html += '<td align="left" class="nick_name">'+ data["data"][i]["nick_name"]+'</td>';

					html +=  data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"] ? '<td><span>--</span></td>' : '<td>'+ data["data"][i]["user_email"]+'</td>';

					html +=  data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"] ? '<td><span>--</span></td>' : '<td>'+ data["data"][i]["user_tel"]+'</td>';

					html += data["data"][i]["user_status"] == 0 ? '<td style="color:red;">锁定</td>' : '<td style="color:green;">正常</td>';
					
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><td colspan="5">暂无符合条件的数据记录</td></tr>';
			}
			$("#member_list tbody").html(html);
		}
	});
}

var is_sub = false;
function addPickupAuditor(){
	var auditor_arr = [];
	var pickupPoint_id = $("#hidden_pickupPoint_id").val();
	$("#member_list tbody tr input[name='sub']:checked").each(function(){
		var auditor = {
			uid : $(this).val()
		};
		auditor_arr.push(auditor);
	});
	if(auditor_arr.length == 0) {
		showTip("请选择要添加的会员","warning"); 
		return false;
	}
	if(!is_sub){
		is_sub = true;
		$.ajax({
			type : "post",
			url : __URL("nspickup/ADMIN_MODULE/shop/addPickupAuditor"),
			data : {
				auditor_arr : JSON.stringify(auditor_arr),
				pickupPoint_id : pickupPoint_id
			},
			success : function(data) {
				if(data["code"] > 0 ){
					showTip(data["message"],'success');
					setInterval(function(){
						location.reload();
					},1000)
				}else{
					showTip(data["message"],'error');
					setInterval(function(){
						location.reload();
					},1000)
				}
			}
		});
	}
}
</script>
{/block}